home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amiga / visualarts / source / context / context.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-02  |  7.7 KB  |  293 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 2.1                        */
  4. /* Copyright 1994-95 Danny Y. Wong  All rights reserved            */
  5. /* Calgary, Alberta (CANADA)                                    */
  6. /* Partial of the code is copyright by Jaba Development            */
  7. /* ******************************************************************** */
  8.  
  9. #include <VisualArts.h>
  10. #include <clib/VisualArts_protos.h>
  11.  
  12. #define ID_ok                                         0
  13. #define ID_HD                                         1
  14. #define ID_cancel                                     2
  15. #define ID_cd                                         3
  16. #define ID_model                                      4
  17. #define ID_ObjID9                                     5
  18.  
  19. #define ContextNumGads                        6
  20.  
  21. #include "Context_func.c" 
  22.  
  23. int okObj(struct VAobject VAObject);
  24. int HDObj(struct VAobject VAObject);
  25. int cancelObj(struct VAobject VAObject);
  26. int cdObj(struct VAobject VAObject);
  27. int modelObj(struct VAobject VAObject);
  28.  
  29. int GetPubScreen(void);
  30. void ClosePubScreen(void);
  31. int OpenContextWindow(char windtitle[]);
  32. void CloseContextWindow(void);
  33. int ContextHandler(void);
  34. int ContextMainHandler(void);
  35. void DrawContextObjs(void);
  36. int main(int argc, char *argv[]);
  37.  
  38. extern UWORD VA_WindHi, VA_WindWid;
  39. UBYTE                *PubScrName = "Workbench";
  40. struct DrawInfo            *ScrDrawInfo = NULL;
  41. APTR                 VisualInfo = NULL;
  42. struct Screen            *Scr = NULL;
  43. struct Window            *ContextWnd = NULL;
  44. struct Gadget            *ContextGList = NULL;
  45. struct Gadget            *ContextGadgets[ContextNumGads];
  46. struct IntuiMessage         ContextMsg;
  47. UWORD                 ContextLeft = 143;
  48. UWORD                 ContextTop = 58;
  49. UWORD                 ContextWidth = 247;
  50. UWORD                 ContextHeight = 72;
  51. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  52. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  53.  
  54. UBYTE *ModelsLabels[] = {
  55.     (UBYTE *)"Amiga 500", 
  56.     (UBYTE *)"Amiga 600", 
  57.     (UBYTE *)"Amiga 1000", 
  58.     (UBYTE *)"Amiga 1200", 
  59.     (UBYTE *)"Amiga 2000", 
  60.     (UBYTE *)"Amiga 2500", 
  61.     (UBYTE *)"Amiga 3000", 
  62.     (UBYTE *)"Amiga 4000", 
  63.     (UBYTE *)"Amiga CDTV", 
  64.     (UBYTE *)"Amiga CD32", 
  65.     NULL
  66. };
  67.  
  68. WORD ContextGadTypes[] = {
  69.     BUTTON_KIND,
  70.     BUTTON_KIND,
  71.     BUTTON_KIND,
  72.     CHECKBOX_KIND,
  73.     LISTVIEW_KIND,
  74.     TEXT_KIND,
  75. };
  76.  
  77. struct NewGadget ContextNGads[] = {
  78.     3, 46, 52, 11, (UBYTE *)"OK",&topaz800, ID_ok, PLACETEXT_IN, NULL, (APTR)okObj,
  79.     134, 32, 87, 11, (UBYTE *)"Hard Drive",&topaz800, ID_HD, PLACETEXT_IN, NULL, (APTR)HDObj,
  80.     170, 46, 52, 11, (UBYTE *)"Cancel",&topaz800, ID_cancel, PLACETEXT_IN, NULL, (APTR)cancelObj,
  81.     195, 1, 26, 11, (UBYTE *)"CD-ROM", &topaz800, ID_cd, PLACETEXT_LEFT, NULL, (APTR)cdObj,
  82.     3, 1, 119, 44, (UBYTE *)"", &topaz800, ID_model, PLACETEXT_ABOVE, NULL, (APTR)modelObj,
  83.     134, 16, 87, 12, (UBYTE *)"", &topaz800, ID_ObjID9, PLACETEXT_LEFT, NULL, NULL,
  84. };
  85.  
  86. ULONG ContextNTags[] = {
  87.     TAG_DONE,
  88.     TAG_DONE,
  89.     TAG_DONE,
  90.     (GTCB_Checked), TRUE, TAG_DONE,
  91.     (GTLV_Labels), NULL, (GTLV_Top), 0, (GTLV_ScrollWidth), 16, (LAYOUTA_Spacing), 0, TAG_DONE,
  92.     (GTTX_Text),(ULONG)"Amiga", (GTTX_Border), TRUE, TAG_DONE,
  93. };
  94.  
  95. UBYTE *ContextContextVars[] = {    /* DO NOT MODIFY */
  96.     (UBYTE *)"2  ",
  97.     (UBYTE *)"0  ",
  98.     (UBYTE *)"2  ",
  99.     (UBYTE *)"1  ",
  100.     (UBYTE *)"0  ",
  101.     (UBYTE *)"Amiga                                                                                                                                                                                                                                           ",
  102. };
  103.  
  104. ULONG ContextContextTypes[] = {
  105.     VA_MoveY , 
  106.     VA_MoveX | VA_MoveY , 
  107.     VA_MoveX | VA_MoveY , 
  108.     VA_MoveX , 
  109.     VA_ExpandX | VA_ExpandY , 
  110.     VA_MoveX | VA_MoveY , 
  111.     TAG_DONE
  112. };
  113.  
  114.  
  115. int GetPubScreen(void)
  116. {
  117.   if (!(Scr = LockPubScreen(PubScrName)))
  118.     return(1L);
  119.  
  120.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  121.     return(2L);
  122.  
  123.   if (!(ScrDrawInfo = GetScreenDrawInfo(Scr)))
  124.     return(3L);
  125.   return(0L);
  126. }
  127.  
  128. void ClosePubScreen(void)
  129. {
  130.   if (VisualInfo)
  131.     FreeVisualInfo(VisualInfo);
  132.   if (Scr)
  133.     UnlockPubScreen(NULL,  Scr);
  134.   if (ScrDrawInfo)
  135.     FreeScreenDrawInfo(Scr,  ScrDrawInfo);
  136. }
  137.  
  138. int OpenContextWindow(char windtitle[80])
  139. {
  140.   struct NewGadget    NewGad;
  141.   struct Gadget       *Gad;
  142.   register UWORD i, j;
  143.   UWORD offsetx = Scr->WBorLeft;
  144.   UWORD offsety = Scr->WBorTop + Scr->Font->ta_YSize + 1;
  145.  
  146.   if (!(Gad = CreateContext(&ContextGList)))
  147.       return(1L);
  148.  
  149.   for (i=0, j=0; i < ContextNumGads; i++)
  150.   {
  151.     CopyMem((char *)&ContextNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  152.  
  153.     NewGad.ng_VisualInfo = VisualInfo;
  154.     NewGad.ng_LeftEdge += offsetx;
  155.     NewGad.ng_TopEdge  += offsety;
  156.  
  157.     ContextGadgets[i] = Gad = CreateGadgetA((ULONG)ContextGadTypes[i], Gad, &NewGad,
  158.     (struct TagItem *)&ContextNTags[j]);
  159.     while (ContextNTags[j])
  160.         j +=2;
  161.     j++;
  162.     if (!Gad)
  163.        return(2L);
  164.   }
  165.   ContextGadgets[1]->Activation |= GACT_TOGGLESELECT;
  166.   if (!(ContextWnd = OpenWindowTags(NULL,
  167.       WA_Left,    ContextLeft,
  168.       WA_Top,     ContextTop,
  169.       WA_Width,    ContextWidth,
  170.       WA_Height,    ContextHeight + kWindowOffSetY,
  171.       WA_NewLookMenus, TRUE,
  172.       WA_IDCMP,    IDCMP_CLOSEWINDOW |  IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_GADGETUP | IDCMP_GADGETDOWN | IDCMP_INTUITICKS ,
  173.       WA_Flags,    WFLG_SIZEGADGET | WFLG_SIZEBRIGHT | WFLG_DEPTHGADGET |
  174.             WFLG_CLOSEGADGET   |  WFLG_SMART_REFRESH | 
  175.              WFLG_RMBTRAP |  WFLG_ACTIVATE | 
  176.              WFLG_DRAGBAR ,
  177.       WA_Gadgets,    ContextGList,
  178.       WA_Title,    windtitle,
  179.       WA_ScreenTitle,    "Visual Arts V2.2 Copyright 1994-95 Danny Y. Wong  All Rights Reserved.",
  180.       WA_PubScreen,    Scr,
  181.       WA_MinWidth,    247,
  182.       WA_MinHeight,    72,
  183.       WA_MaxWidth,    640,
  184.       WA_MaxHeight,    200,
  185.       TAG_DONE)))
  186.           return(3L);
  187.  
  188.   CreateContextLists();
  189.   GT_RefreshWindow(ContextWnd, NULL);
  190.   RefreshGadgets(ContextGadgets[0], ContextWnd, NULL);
  191.   GT_SetGadgetAttrs(ContextGadgets[4], ContextWnd, NULL,
  192.      GTLV_Labels, ContextLists[0], TAG_END);
  193.   VA_WindHi  = ContextWnd->Height;
  194.   VA_WindWid = ContextWnd->Width;
  195.   InitLayoutVars(ContextContextTypes, ContextContextVars);
  196.   return(0L);
  197. }
  198.  
  199. void CloseContextWindow(void)
  200. {
  201.   if (ContextWnd)
  202.     CloseWindow(ContextWnd);
  203.   if (ContextGList)
  204.     FreeGadgets(ContextGList);
  205. }
  206.  
  207. int ContextHandler(void)
  208. {
  209.   struct IntuiMessage    *msg;
  210.   struct VAobject    VAObject;
  211.   int running    = 1;
  212.   int rc    = 0;
  213.   int (*func)(struct VAobject VAObject);
  214.   ULONG class;
  215.   UWORD code;
  216.  
  217.   while (msg=GT_GetIMsg(ContextWnd->UserPort))
  218.   {
  219.     CopyMem((char *)msg, (char *)&ContextMsg, (long)sizeof(struct IntuiMessage));
  220.     class = msg->Class;
  221.     code  = msg->Code;
  222.  
  223.     VAObject.va_Window = (struct Window *)ContextWnd;
  224.     VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  225.     VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  226.     VAObject.va_Flags = 0;
  227.     VAObject.va_UserData = 0;
  228.  
  229.     GT_ReplyIMsg(msg);
  230.     switch(class)
  231.     {
  232.  
  233.       case IDCMP_NEWSIZE:
  234.        rc= VA_GadLayout(ContextWnd, ContextGList, ContextGadgets,
  235.          ContextContextTypes, ContextGadTypes,
  236.          (struct NewGadget *)&ContextNGads, ContextNTags, ContextLists, ContextContextVars);
  237.        break;
  238.  
  239.       case IDCMP_CLOSEWINDOW:
  240.          return(0);
  241.          break;
  242.  
  243.       case IDCMP_GADGETDOWN:    /* GADGETDOWN is for MX gadgets */
  244.  
  245.       case IDCMP_GADGETUP:
  246.         func = (void *)((struct Gadget *)ContextMsg.IAddress)->UserData;
  247.         if (func != NULL)
  248.           running =  func(VAObject);
  249.         break;
  250.  
  251.     }
  252.   }
  253.   return(running);
  254. }
  255.  
  256. int ContextMainHandler(void)
  257. {
  258.   int running = 1;
  259.   ULONG windsig, signals;
  260.  
  261.   windsig = 1L << ContextWnd->UserPort->mp_SigBit;
  262.  
  263.   while (running == 1)
  264.   {
  265.     signals = Wait( windsig );
  266.     if (signals & windsig)
  267.     {
  268.       running = ContextHandler();
  269.     }
  270.   }
  271.   return(running);
  272. }
  273.  
  274. int main(int argc, char *argv[])
  275. {
  276.   int rc;
  277.  
  278.   if (!(GetPubScreen()))
  279.   {
  280.     for (rc=0; rc < 1; rc++)
  281.       ContextLists[rc]=GetNewList();
  282.     if (!(OpenContextWindow("Context Sensitive")))
  283.     {
  284.       rc = ContextMainHandler();
  285.       CloseContextWindow();
  286.     }
  287.     for (rc=0; rc < 1; rc++)
  288.       FreeList(ContextLists[rc]);
  289.     ClosePubScreen();
  290.   }
  291.   return(0L);
  292. }
  293.